#pragma once

#include <QLabel>
#include <QListWidgetItem>
#include <QMainWindow>
#include "ChatWindow.h"
#include "Client.h"

typedef QHash<QString, ChatWindow*> Chats;

namespace Ui {
    class MainWindow;
}

// 主窗口
class MainWindow: public QMainWindow {
    Q_OBJECT

    private: Ui::MainWindow* ui;        // 界面
    private: Chats mChats;              // 聊天窗口集合
    private: Client* mClient;           // 客户端
    private: QLabel mLabelFriendCount;  // "好友数"标签
    private: QLabel mLabelStatus;       // "状态"标签

    public: explicit MainWindow(QWidget* parent = nullptr);
    public: ~MainWindow();
    private: void addAllFriends(LogonResult*);
    private: void addOneFriend(const char*, int, bool isOnline = true);
    private: void changeState(bool);
    private: void clearChatWindow();
    private: ChatWindow* getChatWindow(const char*);
    private: void getResultMessage(ResultCode, QString*);
    private slots: void on_buttonAddFriend_triggered();
    private slots: void on_buttonLogoff_triggered();
    private slots: void on_buttonLogon_triggered();
    private slots: void on_buttonMChat_triggered();
    private slots: void on_buttonReg_triggered();
    private slots: void on_userListView_itemDoubleClicked(QListWidgetItem *item);
    private slots: void onChatC2S(ChatInfo*);
    private slots: void onChatS2C(ChatInfo*);
    private slots: void onFriendLogoff(LogoffRequest*);
    private slots: void onFriendLogon(FriendLogon*);
    private slots: void onGetAddFriendRequest(AddFriendRequest*);
    private slots: void onGetAddFriendResult(AddFriendResult*);
    private slots: void onGetLogonResult(LogonResult*);
    private slots: void onGetRegResult(RegResult*);

};
